package com.polaris.live.adapter

import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.AdapterFreeGiftUserHeadBinding
import com.polaris.live.im.sfs.bean.live.ext.UserBasicVo
import com.polaris.live.utils.image.ImageUtils

/**
 * FreeGiftUserHeadAdapter
 *
 * @author Created by 半仙 on 2024/11/28/028 16:07
 */
class FreeGiftUserHeadAdapter : BaseBindingAdapter<AdapterFreeGiftUserHeadBinding, UserBasicVo>() {

    private var mSelectPosition = 0

    override fun convert(holder: VBViewHolder<AdapterFreeGiftUserHeadBinding>, item: UserBasicVo) {
        holder.vb.apply {
            Glide.with(context).load(ImageUtils.imgPath(item.avatar)).transform(CircleCrop()).into(ivHeadView)
            if (mSelectPosition == holder.absoluteAdapterPosition) {
                ivSelectBack.visibility = View.VISIBLE
            } else {
                ivSelectBack.visibility = View.GONE
            }
        }
    }

    fun setSelectPosition(position: Int) {
        mSelectPosition = position
        notifyDataSetChanged()
    }

    fun getSelectItem() = data.getOrNull(mSelectPosition)

}